package com.myidis.servlet;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.myidis.entity.AnalysisResult;
import com.myidis.entity.Quota;
import com.myidis.entity.User;
import com.myidis.mapper.AnalysisResultMapper;
import com.myidis.response.AnalysisResult_Res;

@Service
public class AnalysisResultServlet {
	@Autowired
	private AnalysisResultMapper anaResMapper;
	@Autowired
	private UserServlet userMapper;
	@Autowired
	private QuotaServlet quotaMapper;
	
	public List<AnalysisResult_Res> searchResult(int baseQuota) {
		
		List<AnalysisResult_Res> res = new ArrayList<AnalysisResult_Res>();
		for(AnalysisResult ana: anaResMapper.getByBase(baseQuota)) {
			Quota base = quotaMapper.getOne(ana.getBaseQuota());
			Quota analysis = quotaMapper.getOne(ana.getAnalysisQuota());
			User user = userMapper.getOne(ana.getAnalyst());
			
			res.add(new AnalysisResult_Res(base, analysis, user, ana));
		}
		
		return res;
	}
	
	public int delete(int id) {
		return anaResMapper.delete(id);
	}
	
	public int deleteAll(int[] ids) {
		int count = 0;
		for(int id: ids)
			count += anaResMapper.delete(id);
		return count;
	}
}

